/*
 * PasswordValidator.java
 *
 * Created on 30 wrzesień 2007, 16:05
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package info.mikrotubula.validators;

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

/**
 *
 * @author Krystian
 */
public class PasswordValidator implements Validator {

    private static final String PASS_REGEX = "^(\\w){6,24}+$";
    
    public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
      Pattern mask =  Pattern.compile(PASS_REGEX);
      String emailField = (String)value; 
      Matcher matcher = mask.matcher(emailField);
	     
    if (!matcher.matches()){
	     	
       FacesMessage message = new FacesMessage();
       message.setDetail("Błędne hasło");
       message.setSummary("Hasło: Hasło musi mieć pomiędzy 6 a 24 znaków i składać się z liter lub cyfr");
       message.setSeverity(FacesMessage.SEVERITY_ERROR);
       throw new ValidatorException(message);
    }
      
 }

    
}
